home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 June
/
CHIP Haziran 2001.iso
/
prog
/
share
/
17
/
dings_e.exe
/
Compiler
/
Bin
/
GFFileSystem.h
< prev
next >
Wrap
C/C++ Source or Header
|
2001-03-02
|
5KB
|
149 lines
//-------GFFileSystem.h------------------------------//
// Global functions for file handling
#ifndef GFFILESYSTEM_H
#define GFFILESYSTEM_H
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <fstream.h>
class GFFileSystem
{
public:
// ------------------------------------------------------------- //
bool GFFileSystem::OpenIn(LPCTSTR file)
// ------------------------------------------------------------- //
{
// if (m_file.is_open()) this->Close();
if (!this->DoesFileExist(file)) return false;
m_file.open (file, ios::in | ios::binary);
return true;
}
// ------------------------------------------------------------- //
bool GFFileSystem::OpenOut(LPCTSTR file)
// ------------------------------------------------------------- //
{
// if (m_file.is_open()) this->Close();
m_file.open(file, ios::out | ios::binary);
return m_file.is_open() ? true : false;
}
// ------------------------------------------------------------- //
void GFFileSystem::Close() {if (m_file.is_open()) m_file.close();}
// ------------------------------------------------------------- //
// ------------------------------------------------------------- //
void GFFileSystem::Write(void* buffer, int bytes)
// ------------------------------------------------------------- //
{
if (m_file.is_open())
m_file.write((char*) buffer, bytes);
}
// ------------------------------------------------------------- //
void GFFileSystem::Read(void* buffer, int bytes)
// ------------------------------------------------------------- //
{
if (m_file.is_open())
m_file.read((char*) buffer, bytes);
}
void GFFileSystem::operator << (int& num) {this->Write(&num, sizeof(num));}
void GFFileSystem::operator << (float& num) {this->Write(&num, sizeof(num));}
void GFFileSystem::operator << (double& num) {this->Write(&num, sizeof(num));}
void GFFileSystem::operator << (DWORD& num) {this->Write(&num, sizeof(num));}
void GFFileSystem::operator << (long& num) {this->Write(&num, sizeof(num));}
void GFFileSystem::operator << (char& num) {this->Write(&num, sizeof(num));}
void GFFileSystem::operator >> (int& num) {this->Read(&num, sizeof(num));}
void GFFileSystem::operator >> (float& num) {this->Read(&num, sizeof(num));}
void GFFileSystem::operator >> (double& num) {this->Read(&num, sizeof(num));}
void GFFileSystem::operator >> (DWORD& num) {this->Read(&num, sizeof(num));}
void GFFileSystem::operator >> (long& num) {this->Read(&num, sizeof(num));}
void GFFileSystem::operator >> (char& num) {this->Read(&num, sizeof(num));}
//---------------------------------------------------------------//
static void DeleteDebug()
//---------------------------------------------------------------//
{
char filename[MAX_PATH];
::GetTempPath(MAX_PATH,filename);
strcat(filename, "\\ErrorLog.txt");
::DeleteFile(filename);
}
//---------------------------------------------------------------//
static void WriteDebug(LPCTSTR text)
//---------------------------------------------------------------//
{
char filename[MAX_PATH];
::GetTempPath(MAX_PATH,filename);
strcat(filename, "\\ErrorLog.txt");
ofstream file(filename, ios::app|ios::out);
file<< text;
file<< "\r\n";
file.close();
}
//---------------------------------------------------------------//
static void WriteDebug(double number)
//---------------------------------------------------------------//
{
char filename[MAX_PATH];
::GetTempPath(MAX_PATH,filename);
strcat(filename, "\\ErrorLog.txt");
ofstream file(filename, ios::app|ios::out);
file<< number;
file<< "\r\n";
file.close();
}
//---------------------------------------------------------------//
static bool DoesFileExist(LPCTSTR filename)
//---------------------------------------------------------------//
{
FILE *filehandle;
if((filehandle=fopen(filename, "rb"))==NULL) return false;
fclose (filehandle);
return true;
}
//---------------------------------------------------------------//
static void MapKeyState()
//---------------------------------------------------------------//
{
BYTE buffer[256];
if (!::GetKeyboardState(buffer))
GFFileSystem::WriteDebug("nO stATE");
GFFileSystem::WriteDebug("KeyState:");
for (int i=0; i<256; i++)
{
// if (buffer[i]>=128) GFFileSystem::WriteDebug(i);
}
}
protected:
fstream m_file;
};
#define g_deldebug() GFFileSystem::DeleteDebug();
#define g_debug(a) GFFileSystem::WriteDebug(a)
#define g_FileExist(a) GFFileSystem::DoesFileExist(a)
#endif